<template>
  <div class="app-container teacher-info-container">
    <el-row>
      <el-col>
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="72px"  >
          <el-form-item label="证书名称" prop="contacts" v-if="enterpriseId === null">
            <el-input width="150px" v-model="queryParams.name" placeholder="请输入证书名称" clearable
                      @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="状态" prop="contacts" v-if="enterpriseId === null">
            <el-select v-model="queryParams.status" placeholder="请选择状态" >
              <el-option v-for="dict in dict.type.honer_status" :key="dict.value" :label="dict.label"
                         :value="dict.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-if="enterpriseId === null">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
          <div class="search-row manager-row">
            <el-form-item label="证书类别" prop="type">
              <div class="manager-tags">
      <span
        v-for="manager in certificateTypeOptions"
        :key="manager.dictValue"
        :class="['manager-tag', queryParams.type === manager.dictValue ? 'active' : '']"
        @click="handleManagerSelect(manager)"
      >
        {{ manager.dictLabel }}
      </span>
              </div>
            </el-form-item>
          </div>
        </el-form>

        <el-row :gutter="10" class="mb8" v-if="!isOpen">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-if="opt!=='details'"
            >新增</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <div style="width: 100%;height: 90vh;overflow:auto; margin-bottom: 30%;padding-bottom: 18%;position: relative;">
        <el-table :cell-style="{ padding: '0px' }" :height="450" border v-loading="loading" :data="managementList"
                  @selection-change="handleSelectionChange" highlight-current-row :row-style="changeColor" :header-cell-style="{'text-align':'center'}">

          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="序" type="index" :index="indexMethod" width="35"/>
          <el-table-column label="状态" align="center" prop="status" width="45">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.honer_status" :value="scope.row.status" />
            </template>
          </el-table-column>
          <el-table-column label="更新时间" align="center" prop="operateTime" width="85" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.operateTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="证书类别" align="center" prop="type" :show-overflow-tooltip="true" width="70">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.certificate_type" :value="scope.row.type" />
            </template>
          </el-table-column>
          <el-table-column label="证书名称" align="left" prop="name" :show-overflow-tooltip="true" width="200"/>
          <el-table-column label="发证时间" align="center" prop="entryTime" width="85" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.entryTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="到期时间" align="center" prop="issuanceTime" width="85" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.issuanceTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="有效期" align="center" prop="effectiveTime" width="70" :show-overflow-tooltip="true" >
            <template slot-scope="scope">
              {{ scope.row.effectiveTime }}年
            </template>
          </el-table-column>
          <el-table-column label="证书规格" align="center" prop="level" :show-overflow-tooltip="true" width="70">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.certificate_level" :value="scope.row.level" />
            </template>
          </el-table-column>
          <el-table-column label="预警时间" align="center" prop="abutmentTime" width="85"
                           :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span :style="{ color: getWarningColor(scope.row.abutmentTime) }">{{ parseTime(scope.row.abutmentTime,
                '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="预警内容" align="left" prop="oneExamineStage" :show-overflow-tooltip="true" width="140"/>
          <el-table-column label="发证机构" align="left" prop="certificateInstitution" :show-overflow-tooltip="true" width="120"/>
          <el-table-column label="服务机构" align="center" prop="serviceInstitu" :show-overflow-tooltip="true" width="70"/>
          <el-table-column label="证书编号" align="left" prop="certificateNo" :show-overflow-tooltip="true" width="150"/>
          <el-table-column label="附件" align="center" prop="list" width="100">
            <template slot-scope="scope">
              <div class="thumbnail-container"   >
                <img v-if="scope.row.fileUrl" :src="scope.row.fileUrl" class="thumbnail-image" alt="附件图片"  @click="handleImageClick(scope.row.fileUrl)"/>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="网址名称" align="center" prop="selectUrl" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <el-button @click="handleClick(scope.row.urlName)" type="text">
                <dict-tag :options="dict.type.honor_urlname" :value="scope.row.urlName" />
              </el-button>
            </template>
          </el-table-column>

          <el-table-column label="创建人" align="center" prop="createId" :show-overflow-tooltip="true" width="85" />
          <el-table-column label="创建时间" align="center" prop="creationTime" :width="85">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.creationTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="100" v-if="opt!=='details'">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row, scope.$index)"
                         title="修改"></el-button>
              <el-button size="mini" type="text" icon="el-icon-s-grid"
                         @click="handleLvli(scope.row)" title="履历"></el-button>
              <el-button  size="mini" type="text" icon="el-icon-delete-solid"
                         @click="handleDelete(scope.row)" title="删除"></el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" @pagination="getList" />
        </div>
        <!-- 内部文本-->
      </el-col>
    </el-row>
    <!--    预览图片-->
    <el-dialog :visible.sync="openImg" width="50%">
      <img :src="previewImageUrl" class="preview-image" alt="预览图片" />
    </el-dialog>

    <!-- 添加或修改荣誉资质信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="730px" append-to-body >
      <el-form ref="form" :model="form" :rules="rules" label-width="90px" :inline="true">
        <div v-if="addSign === 1">
          <el-descriptions title="">
            <el-descriptions-item label="序号">
              <el-tag size="medium">{{ form.index }}</el-tag>
            </el-descriptions-item>
          </el-descriptions>
        </div>
        <el-form-item label="发证时间" prop="entryTime" label-width="110px">
          <el-date-picker clearable v-model="form.entryTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择发证时间"
                          style="width: 202.5px" class="custom-date-picker" >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预警时间" prop="abutmentTime" label-width="110px">
          <el-date-picker clearable v-model="form.abutmentTime" type="date" value-format="yyyy-MM-dd"
                          placeholder="请选择预警时间" style="width: 202.5px"></el-date-picker>
        </el-form-item>
        <el-form-item label="证书名称" prop="name" label-width="110px">
          <el-input v-model="form.name" placeholder="请输入证书名称" style="width: 202.5px" maxlength="20" show-word-limit />
        </el-form-item>
        <el-form-item label="证书编号" prop="certificateNo" label-width="110px">
          <el-input v-model="form.certificateNo" placeholder="请输入证书编号" style="width: 202.5px" maxlength="25" show-word-limit />
        </el-form-item>
        <el-form-item label="证书类别" prop="type" label-width="110px">
          <el-select v-model="form.type" placeholder="请选择证书类别" style="width: 202.5px">
            <el-option v-for="dict in dict.type.certificate_type" :key="dict.value" :label="dict.label"
                       :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="证书规格" prop="level" label-width="110px">
          <el-select v-model="form.level" placeholder="请选择证书规格" style="width: 202.5px">
            <el-option v-for="dict in dict.type.certificate_level" :key="dict.value" :label="dict.label"
                       :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="服务机构" prop="serviceInstitu" label-width="110px">
          <el-input v-model="form.serviceInstitu" placeholder="请输入服务机构" style="width: 202.5px" maxlength="20"
                    show-word-limit />
        </el-form-item>
        <el-form-item label="发证机构" prop="certificateInstitution" label-width="110px">
          <el-input v-model="form.certificateInstitution" placeholder="请输入发证机构" style="width: 202.5px"  maxlength="20" show-word-limit/>
        </el-form-item>
        <el-form-item label="证书到期日" prop="issuanceTime" label-width="110px">
          <el-date-picker clearable v-model="form.issuanceTime" type="date" value-format="yyyy-MM-dd"
                          placeholder="请选择证书到期日" style="width: 202.5px" @change="getEffectiveTime">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="剩余有效时间" prop="effectiveTime" label-width="110px">
          <el-input v-model="form.effectiveTime" placeholder="剩余有效时间" style="width: 202.5px" type="number"
                    pattern="[0-9]*" :min="0" disabled="true"/>
          <span style="margin-left: 5px;">年</span>
        </el-form-item>
        <!--        <el-form-item label="查询网址" prop="selectUrl" label-width="110px">-->
        <!--          <el-input v-model="form.selectUrl" placeholder="请输入查询网址" style="width: 202.5px" maxlength="100" show-word-limit/>-->
        <!--        </el-form-item>-->
        <el-form-item label="网址名称" prop="urlName" label-width="110px">
          <el-select v-model="form.urlName" placeholder="请选择状态" style="width: 202.5px">
            <el-option v-for="dict in dict.type.honor_urlname" :key="dict.value" :label="dict.label"
                       :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="状态" prop="status" label-width="110px">
          <el-select v-model="form.status" placeholder="请选择状态" style="width: 202.5px">
            <el-option v-for="dict in dict.type.honer_status" :key="dict.value" :label="dict.label"
                       :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="预警内容" prop="oneExamineStage" label-width="110px">
          <el-input v-model="form.oneExamineStage" placeholder="请输入预警内容"   type="textarea" show-word-limit style="width: 525px"/>
        </el-form-item>
        <el-form-item label="创建时间" prop="creationTime" label-width="110px">
          <el-date-picker clearable v-model="form.creationTime" type="date" value-format="yyyy-MM-dd"
                          placeholder="请选择时间" style="width: 202.5px" disabled="true">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建人" prop="createId" label-width="110px">
          <el-input v-model="form.createId" placeholder="请输入创建人" disabled="true" style="width: 202.5px" />
        </el-form-item>
        <el-form-item label="附件" prop="uploadFile" label-width="110px">
          <file-view v-if="showUpload" :type="typeSelectHonor" :businessId="form.uploadFile"
                     :businessCode="uploadCode"></file-view>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

    <!--    履历对话框-->
    <el-dialog title="履历列表" :visible.sync="resumeOpen" width="1200px" @close="resetReusumeClose()">
      <el-row>
        <!--            <el-col :span="5">-->
        <!--              <MainType :typeCode="typeCodeResume" @getNode="getNodeResume"></MainType>-->
        <!--            </el-col>-->
        <el-col :span="24">
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddResume">新增</el-button>
            </el-col>
          </el-row>
          <el-table :row-style="{ height: '30px' }" :cell-style="{ padding: '0px' }" border v-loading="loading"
                    :data="resumeList" @selection-change="handleSelectionChange">
            <el-table-column label="序号" type="index" :index="indexMethod" />
            <el-table-column label="关联方式" align="center" prop="concat" :show-overflow-tooltip="true" />
            <el-table-column label="创建时间" align="center" prop="honorTime" width="120" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.honorTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="项目名称" align="center" prop="projectId" :show-overflow-tooltip="true" />
            <el-table-column label="责任人" align="center" prop="dutyPerson" />
            <el-table-column label="发证机构" align="center" prop="certificateInstitution" :show-overflow-tooltip="true" />
            <el-table-column label="服务机构" align="center" prop="serviceInstitu" :show-overflow-tooltip="true" />
            <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
            <el-table-column label="创建人" align="center" prop="createId" :show-overflow-tooltip="true" width="100" />
            <el-table-column label="状态" align="center" prop="status" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.honer_status" :value="scope.row.status" />
              </template>
            </el-table-column>
            <el-table-column label="附件" align="center" prop="uploadFile">
              <template slot-scope="scope">
                <el-button @click.stop="handlePictureCardPreviewResume(scope.row.uploadFile)" size="small"
                           type="text" v-if="scope.row.fileUrl!== '' && scope.row.fileUrl !== null">附件</el-button>
                <el-button  size="small"
                            type="text" v-else>无附件</el-button>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
              <template slot-scope="scope">
                <el-button size="mini" type="text" icon="el-icon-edit"
                           @click="handleUpdateLvli(scope.row, scope.$index)"  title="修改"></el-button>
                <el-button size="mini" type="text" icon="el-icon-delete"
                           @click="handleDeleteLvli(scope.row)" title="删除"></el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination v-show="totalResume > 0" :total="totalResume" :page.sync="queryResume.pageNum"
                      :limit.sync="queryResume.pageSize" @pagination="getResumeList" />
        </el-col>
      </el-row>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="openUser" width="1200px" append-to-body>
      <div style="height:85vh">
        <el-scrollbar>

          <div class="content-box">
            <BusinessInfo :markAs="1" @change="close" @ok="selectEnterprise" :enterprise="1">

            </BusinessInfo>
          </div>
        </el-scrollbar>
      </div>
    </el-dialog>

    <!-- 添加或修改荣誉资质履历对话框 -->
    <el-dialog title="新增/编辑" :visible.sync="openResume" width="700px" append-to-body @close="closeDig">
      <div v-if="resumeSign === 1">
        <el-descriptions title="">
          <el-descriptions-item label="序号">
            <el-tag size="medium">{{ index }}</el-tag>
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <el-form ref="formResume" :model="formResume" :rules="rulesResume" label-width="90px" :inline="true">
        <el-form-item label="关联方式" prop="concat">
          <el-input v-model="formResume.concat" placeholder="请输入关联方式" maxlength="30" />
        </el-form-item>
        <el-form-item label="项目名称" prop="projectId">
          <el-input v-model="formResume.projectId" placeholder="请输入项目名称" maxlength="30" />
        </el-form-item>
        <el-form-item label="责任人" prop="dutyPerson">
          <el-input v-model="formResume.dutyPerson" placeholder="请输入责任人" maxlength="15" />
        </el-form-item>
        <el-form-item label="发证机构" prop="certificateInstitution">
          <el-input v-model="formResume.certificateInstitution" placeholder="请输入发证机构" maxlength="20" />
        </el-form-item>
        <el-form-item label="服务机构" prop="serviceInstitu">
          <el-input v-model="formResume.serviceInstitu" placeholder="请输入服务机构" maxlength="20" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="formResume.remark" placeholder="请输入备注" maxlength="20" show-word-limit/>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="formResume.status" placeholder="请选择状态" style="width: 178px">
            <el-option v-for="dict in dict.type.honer_status" :key="dict.value" :label="dict.label"
                       :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间" prop="honorTime">
          <el-date-picker clearable v-model="formResume.honorTime" type="date" value-format="yyyy-MM-dd"
                          placeholder="请选择时间" style="width: 178px" disabled="true">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建人" prop="createId">
          <el-input v-model="formResume.createId" placeholder="请输入创建人" disabled="true" />
        </el-form-item>
        <el-form-item label="附件" prop="uploadFile">
          <file-view v-if="show" :type="typeSelect" :businessId="formResume.uploadFile" :businessCode="businessCode"
                     @getFile="getFile"></file-view>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormResume">确 定</el-button>
        <el-button @click="cancelResume">关 闭</el-button>
      </div>
    </el-dialog>
    <!--   荣誉资质 附件展示对话框-->
    <el-dialog title="查看附件" :visible.sync="openFileList" width="500px" append-to-body v-if="openFileList">
      <UploadFile :upload-id="uploadId" :business-code="uploadCode"></UploadFile>
    </el-dialog>
    <!--   履历 附件展示对话框-->
    <el-dialog title="查看附件" :visible.sync="resumeFileList" width="500px" append-to-body v-if="resumeFileList">
      <UploadFile :upload-id="uploadId" :business-code="businessCode"></UploadFile>
    </el-dialog>
    <el-dialog :visible.sync="dialogVisible" append-to-body>
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
  </div>
</template>

<script>
import { treeHonor, reviceHonor } from "@/api/honor/management";
import { listTeacherHonor, getTeacherHonor, delTeacherHonor, addTeacherHonor, updateTeacherHonor } from "@/api/teacherHonor/teacherHonor";
import { getToken } from '@/utils/auth'
import { listInfo } from "@/api/enterprise/info";
import BusinessInfo from "../../enterprise/info/index.vue";
import { listResume, getResume, delResume, addResume, updateResume } from "@/api/honor/resume";
import dia from "../../enterprise/seas/dialog.vue";
import FileView from "@/components/FileView/index"
import MainType from "@/components/MainType/index"
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listType } from "@/api/maintype/type";
import UploadFile from "../../upload/index.vue";
import {getDicts} from "@/api/system/dict/data";
export default {
  name: "teacher",
  components: { UploadFile, dia, BusinessInfo, FileView, MainType, Treeselect },
  dicts: ['certificate_type', 'certificate_level', 'honer_status', 'honor_urlname','teacher_honorsr_type'],
  props: {
    enterpriseId: {
      type: String,
      default: null
    },
    enterpriseName: {
      type: String,
      default: null
    },
    isShow: {
      type: String,
      default: ""
    },
    isOpen: {
      type: Boolean,
      default: false
    },
    orgId: {
      type: String,
      default: null
    },
    opt:{
      type:String,
      default:null
    }
  },

  data() {

    return {
      headers: {
        'Authorization': 'Bearer ' + getToken()
      },
      //主分类
      typeCode: 'honor',
      typeCodeResume: 'honor_resume',
      uploadCode: 'honor',
      showUpload: false,
      typeSelectHonor: 0,
      // 遮罩层
      loading: true,
      openImg:false,
      previewImageUrl:null,
      ImgDig: false,
      dialogImageUrl: null,
      certificateTypeOptions:[],
      // 选中数组
      ids: [],
      // 证书类型选项
      deptOptions: undefined,
      defaultProps: {
        children: "children",
        label: "label"
      },
      //附件预览
      dialogVisible: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 荣誉资质履历表格数据
      resumeList: [],
      // 荣誉资质信息表格数据
      managementList: [],
      // 弹出层标题
      title: "",
      //主分类
      options: null,
      //主分类:履历
      optionsResume: null,
      // 是否显示弹出层
      open: false,
      show: false,
      openUser: false,
      //父传子的履历附件标志位
      typeSelect: 0,
      //当前履历总数
      totalResume: 0,
      // 查询参数
      queryParams: {
        name: null,
        type: '',
        customerId: null,
        level: null,
        status: null,
        pageNum: 1,
        pageSize: 15,
        classificationId: null,
        organizationId: null,
        enterpriseName: null
      },
      //查询条件，履历
      queryResume: {
        pageNum: 1,
        pageSize: 15,
        honorId: null,
        classificationId: null
      },
      //履历id
      resumeId: null,

      //传递给子类的表单数据
      formResume: {},
      //新增履历弹框
      openResume: false,
      // 表单参数
      form: {},
      //附件对话框
      openFileList: false,
      resumeFileList: false,
      uploadId: null,
      //控制修改和新增
      addSign: 0,
      //履历传递序号
      index: null,
      //履历对话框
      resumeOpen: false,
      //新增还是删除：履历
      resumeSign: 0,
      businessCode: 'resume',
      // 表单校验
      rules: {
        entryTime: [
          { required: true, message: '请选择发证时间', trigger: 'change' },
        ],
        abutmentTime: [
          { required: true, message: '请选择预警时间', trigger: 'change' }
        ],
        name: [
          { required: true, message: '请输入证书名称', trigger: 'blur' }
        ],
        issuanceTime: [
          { required: true, message: '请选择证书到期时间', trigger: 'change' },
          {
            validator: (rule, value, callback) => {
              const entryTime = this.form.entryTime;
              const issuanceTime = this.form.issuanceTime;
              if (issuanceTime && issuanceTime < entryTime) {
                callback(new Error('证书到期时间不能小于发证时间'));
              } else {
                callback();
              }
            },
            trigger: 'blur',
          },
        ],
      },
      rulesResume: {
        concat: [
          { required: true, message: '请输入关联方式', trigger: 'blur' }
        ],
        projectId: [
          { required: true, message: '请输入项目名称', trigger: 'blur' }
        ],
        certificateInstitution: [
          { required: true, message: '请输入发证机构', trigger: 'blur' }
        ],
        serviceInstitu: [
          { required: true, message: '请输入服务机构', trigger: 'blur' }
        ]
      },

      enterpriseList: [],
    };
  },
  created() {
    this.getDeptTree();
    this.getList();
    this.getEnterInfoList();
    this.listTypeResume();
    this.getDicts();
  },
  //监听子组件弹框的boolean值,用于关闭弹窗后，数据重新加载
  watch: {
    openResume: function (newValue, oldValue) {
      // 在someValue发生变化时执行的操作
      console.log('someValue changed:', newValue);
      // 调用您想要执行的方法
      this.getResumeList();
    },
    // enterpriseId:function (newValue,oldVal){
    //
    //   this.getList();
    // }
    orgId: function (newValue, oldValue) {
      console.log("新值:" + newValue)
      this.queryParams.organizationId = newValue
      this.getList();
    },
  },


  methods: {
    //获取树节点数据
    listType() {
      listType({ typeCode: 'honor' }).then(res => {
        this.options = res.data;
      })
    },
    //查询荣誉资质所有类型
    getDicts() {
      getDicts('certificate_type').then(res => {
        this.certificateTypeOptions = res.data;
        //再插入一个
        this.certificateTypeOptions.unshift({
          dictLabel:"无",
          dictValue:-1
        });
      });
    },
    handleManagerSelect(manager) {
      if (this.queryParams.type === manager.dictValue) {
        this.queryParams.type = null; // 再次点击取消选择
      } else {
        this.queryParams.type = manager.dictValue;
      }
      this.handleQuery(); // 触发搜索

    },
    changeColor({ row }) {
      const currentDate = new Date();
      const selectedDate = new Date(row.abutmentTime);
      // 计算毫秒级的时间差
      const timeDifference = selectedDate - currentDate;
      // 将毫秒转换为天数
      const daysDifference = timeDifference / (1000 * 60 * 60 * 24);
      // 如果时间差小于3个月（约90天），返回红色，否则返回空字符串
      if (daysDifference < 90) {
        return {
          color: "orange",
          height: '30px' // 这个return的就是样式 可以是color 也可以是backgroundColor
        }
      } else {
        return {
          height: '30px' // 这个return的就是样式 可以是color 也可以是backgroundColor
        }
      }
    },
    //获取树节点数据
    listTypeResume() {
      listType({ typeCode: 'honor_resume' }).then(res => {
        this.optionsResume = res.data;
      })
    },
    /** 查询荣誉资质信息列表 */
    getList() {
      this.loading = true;
      if (this.enterpriseId != null) {
        this.queryParams.customerId = this.enterpriseId
        this.queryParams.enterpriseName = this.enterpriseName
      }
      this.queryParams.organizationId = this.orgId;
      console.log(this.queryParams)
      listTeacherHonor(this.queryParams).then(response => {
        this.managementList = response.rows;
        console.log(this.managementList)
        this.total = response.total;
        this.loading = false;
      });
    },
    handleImageClick(imageUrl) {
      this.previewImageUrl = imageUrl;
      this.openImg = true;
    },
    // 获取有效时间，通过获取证书到期日 - 当前时间等于多少年的有效时间
    getEffectiveTime() {
      // 证书到期日
      let issuanceTime = new Date(this.form.issuanceTime);
      // 获取当前时间
      let currentTime = new Date();
      // 获取当前时间的时间戳
      let currentInstant = currentTime.getTime();
      // 获取证书到期日的时间戳
      let expiryInstant = issuanceTime.getTime();
      // 格式化当前日期为 YYYY-MM-DD 格式
      let currentDate = new Date(currentInstant).toISOString().split('T')[0];
      // 格式化证书到期日期为 YYYY-MM-DD 格式
      let expiryDate = new Date(expiryInstant).toISOString().split('T')[0];
      // 计算剩余年数
      let yearsRemaining = Math.floor((new Date(expiryDate).getTime() - new Date(currentDate).getTime()) / (1000 * 60 * 60 * 24 * 365));
      // 不足一年按 0 年算
      if (yearsRemaining < 1) {
        yearsRemaining = 0;
      }
      // 将剩余年数赋值给表单的有效时间字段
      this.form.effectiveTime = yearsRemaining;
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    getFile(data) {
      console.log(JSON.stringify(data))
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.type = data.id;
      this.handleQuery();
    },
    //荣誉资质:树点击事件
    getNode(data) {
      console.log(data)
      if (data.parentId != '00000000-0000-0000-0000-000000000000') {
        this.queryParams.classificationId = data.id
      } else {
        this.queryParams.classificationId = null;
      }
      this.getList()
    },
    //履历:树点击事件
    getNodeResume(data) {
      console.log(data)
      if (data.parentId != '00000000-0000-0000-0000-000000000000') {
        this.queryResume.classificationId = data.id
      } else {
        this.queryResume.classificationId = null;
      }
      this.getResumeList();
    },
    getDeptTree() {
      treeHonor().then(response => {
        this.deptOptions = response.data;
      });
    },
    getWarningColor(abutmentTime) {
      const currentDate = new Date();
      const selectedDate = new Date(abutmentTime);
      // 计算毫秒级的时间差
      const timeDifference = selectedDate - currentDate;
      // 将毫秒转换为天数
      const daysDifference = timeDifference / (1000 * 60 * 60 * 24);
      // 如果时间差小于3个月（约90天），返回红色，否则返回空字符串
      return daysDifference < 90 ? "red" : "";
    },
    //履历对话框
    handleLvli(row) {
      this.reset();
      const id = row.id || this.ids
      this.queryResume.honorId = row.id;
      this.resumeId = row.id;
      this.getResumeList();
      this.resumeOpen = true;
    },
    handleLvRevice(row) {
      this.$confirm("是否接收该荣誉资质证书？", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          reviceHonor(row.id).then(res => {
            if (res.code === 200) {
              this.$message.success("接收成功");
              this.getList();
            } else {
              this.$message.error("接收失败");
              this.getList();
            }
          })
        })
    },
    handleUpdateLvli(row, index) {
      this.resumeId = row.id;
      this.openResume = true;
      this.index = index + 1;
      this.resumeSign = 1;
      this.typeSelect = 1;
      this.listTypeResume();
      getResume(this.resumeId).then(res => {
        this.formResume = res.data;
        this.show = true;
      })
    },
    handleClick(url) {
      if (!url.startsWith('http://') && !url.startsWith('https://')) {
        // 如果没有协议，添加默认的http://协议
        url = 'http://' + url;
      } window.open(url, '_blank');
    },
    //新增履历
    handleAddResume() {
      this.resetResume();
      this.formResume.uploadFile = new Date().getTime()
      this.formResume.honorTime = new Date();
      this.formResume.createId = this.$store.state.user.name;
      this.formResume.classificationId = '650c44e1-b575-4b62-9d54-1ba9d1e8abb7'
      this.listTypeResume();
      this.openResume = true;
      this.resumeSign = 0;
      //弹出框选择，默认为0
      this.typeSelect = 0;
      this.show = true;

    },
    //保存
    submitFormResume() {
      console.log(JSON.stringify(this.formResume))
      this.$refs["formResume"].validate(valid => {
        if (valid) {
          if (this.formResume.id != null) {
            this.formResume.honorId = this.honorId;
            console.log(this.formResume.uploadFile)
            updateResume(this.formResume).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.getResumeList();
              this.openResume = false;
              this.open = false;
              this.typeSelect = null;
              this.resetResume();
              this.show = false;

            });
          } else {
            this.formResume.honorId = this.queryResume.honorId
            this.formResume.createId = this.$store.state.user.name;
            console.log(this.formResume)
            addResume(this.formResume).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.getResumeList();
              this.openResume = false;
              this.open = false;
              this.typeSelect = null;
              this.resetResume();
              this.show = false;

            });
          }
        }
      });
    },
    //取消履历
    cancelResume() {
      this.openResume = false;
      this.show = false;
      this.resetResume();
    },
    closeDig() {
      this.openResume = false;
      this.show = false;
      this.resetResume();
    },
    resetResume() {
      this.formResume = {
        id: null,
        honorId: null,
        concat: null,
        honorTime: null,
        projectId: null,
        dutyPerson: null,
        certificateInstitution: null,
        serviceInstitu: null,
        remark: null,
        uploadFile: null
      };
    },
    /** 查询荣誉资质履历列表 */
    getResumeList() {
      this.loading = true;
      console.log(this.queryResume)
      listResume(this.queryResume).then(response => {
        this.resumeList = response.rows;
        console.log(this.resumeList)
        this.totalResume = response.total;
        this.loading = false;
      });
    },
    handleExceed(files, fileList) {
      this.$message.warning("只允许上传一个文件");
    },
    beforeUpload(file) {
      let size10M = file.size / 1024 / 1024 < 20
      if (!size10M) {
        this.$message.warning('上传文件大小不能超过 20MB!');
        return false
      }
    },
    //企业信息查询
    getEnterInfoList() {
      listInfo().then(res => {
        this.enterpriseList = res.rows;

      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.showUpload = false;
      this.reset();
    },
    enterprise() {
      this.openUser = true;
      this.title = '选择';
    },
    close() {
      this.openUser = false
    },
    selectEnterprise(data) {
      this.form.customerId = data.enterpriseId
      this.form.enterpriseName = data.enterpriseName
      console.log(this.form)
      this.close()
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.showUpload = true
      this.typeSelectHonor = 0;
      this.form.uploadFile = new Date().getTime();
      this.open = true;
      this.addSign = 0;
      this.title = "新增";
      this.form.createId = this.$store.state.user.name;
      if (this.queryParams.classificationId === null) {
        this.form.classificationId = '650c44e1-b575-4b62-9d54-1ba9d1e8abb7'
      } else {
        this.form.classificationId = this.queryParams.classificationId;
      }
      this.listType();
      //获取当前时间
      this.form.creationTime = new Date();
      console.log(this.$store.state.user.name)
      if (this.enterpriseId != null) {
        this.form.enterpriseName = this.enterpriseName
        this.form.customerId = this.enterpriseId
      }
    },
    //拿到服务器返回的数据
    handle_success(res) {
      this.form.list.push(res);
      console.log(this.form.list)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        name: null,
        type: '',
        level: null,
        pageNum: 1,
        pageSize: 15,
      };
      this.handleQuery();
    },
    //履历重置
    resetReusume() {
      this.queryResume.classificationId = null
      this.getResumeList();
    },
    resetReusumeClose() {
      this.queryResume.classificationId = null
    },
    /** 修改按钮操作 */
    handleUpdate(row, index) {
      this.reset();
      const id = row.id || this.ids
      getTeacherHonor(id).then(response => {
        this.form = response.data;
        this.form.index = index + 1;
        this.form.effectiveTime=row.effectiveTime;
        this.showUpload = true;
        this.typeSelectHonor = 1;
        if (this.form.uploadFile === null) {
          this.form.uploadFile = new Date().getTime();
        }
        this.form.list = [];
        console.log(this.form)
        this.listType();
        this.open = true;
        this.title = "修改";
        this.addSign = 1;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTeacherHonor(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.showUpload = false;
              this.getList();
              this.$emit('change');
            });
          } else {
            addTeacherHonor(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.form.fileList = null;
              this.showUpload = false;
              this.getList();
              this.$emit('change');
            });
          }
        }
      });
    },
    //序号展示
    indexMethod(index) {
      return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除荣誉资质信息名称为"' + row.name + '"的数据项？').then(function () {
        return delTeacherHonor(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    handleDeleteLvli(row){
      const ids = row.id || this.ids;
      console.log(ids)
      this.$modal.confirm('是否确认删除该履历的数据项？').then(function () {
        return delResume(ids);
      }).then(() => {
        this.getResumeList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    handlePictureCardPreview(url) {
      this.dialogVisible = true;
      this.dialogImageUrl = url;
      // this.uploadId = id;
      // this.openFileList = true;
    },
    handlePictureCardPreviewResume(id) {
      this.uploadId = id;
      this.resumeFileList = true;
    }
  }
};
</script>
<style scoped lang="scss">
.teacher-info-container {
  overflow-y: auto;
  overflow-x: auto;
  padding: 16px;
  max-width: 100%;
  max-height: 90vh;
  box-sizing: border-box;
}

.thumbnail-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  /* 确保容器高度占满单元格 */
}

.thumbnail-image {
  object-fit: cover;
  border: 1px solid #ccc; /* 可选，添加边框样式 */
  height: 30px;
}

.preview-image {
  width: 100%;
  height: auto;
}
.manager-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;

  .manager-tag {
    padding: 4px 12px;
    border: 1px solid #DCDFE6;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s;

    &:hover {
      border-color: #409EFF;
      color: #409EFF;
    }

    &.active {
      background-color: #409EFF;
      border-color: #409EFF;
      color: #fff;
    }
  }
}
</style>
